<?php
class CommonData {
	
	static function getCategorys($db){
		$catTable = new BaseDao($db,'goods_category','cat_id');
		$categorys = $catTable->getAll(null, null,array('is_show desc','sort_order asc'));
		$newcategorys = array();
		foreach ($categorys as $category0){
			if($category0['parent_id'] == 0){
				$childs0 = array();
				foreach ($categorys as $category1){
					if($category0['cat_id'] == $category1['parent_id']){
						$childs1 = array();
						foreach ($categorys as $category2){
							if($category1['cat_id'] == $category2['parent_id']){
								$childs1[] = $category2;
							}
						}
						$category1['childs'] = $childs1;
						$childs0[] = $category1;
					}
				}
				$category0['childs'] = $childs0;
				$newcategorys[] = $category0;
			}
		}
		return $newcategorys;
	}
	
	
	static function getCategoryMap($db){
		$catTable = new BaseDao($db,'goods_category','cat_id');
		$categorys = $catTable->getAll(null, null,array('is_show desc','sort_order asc'));
	
		$newcategorys = array();
		foreach ($categorys as $category){
			$newcategorys[$category['cat_id']] = $category;
		}
		return $newcategorys;
	}
	
	
	
	static function getAttrs($name1,$name2){
		$name1 = (isset($name1) && trim($name1) !=='')?trim($name1):'';
		$name2 = (isset($name2) && trim($name2) !=='')?trim($name2):'';
		return $name1.':'.$name2;
	}
	
	static function attrs2array($attrs){
		$arr = array();
		$attrs = explode(':',$attrs);
		$arr['name1'] = $attrs[0];
		$arr['name2'] = $attrs[1];
		return $arr;
	}
}
?>